package com.love.usedcar.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.love.common.log.annotation.Log;
import com.love.common.log.enums.BusinessType;
import com.love.common.security.annotation.RequiresPermissions;
import com.love.usedcar.domain.UsedCarTransaction;
import com.love.usedcar.service.IUsedCarTransactionService;
import com.love.common.core.web.controller.BaseController;
import com.love.common.core.web.domain.AjaxResult;
import com.love.common.core.utils.poi.ExcelUtil;
import com.love.common.core.web.page.TableDataInfo;

/**
 * 车辆交易记录（管理车辆交易流程）Controller
 * 
 * @author love
 * @date 2025-10-01
 */
@RestController
@RequestMapping("/transaction")
public class UsedCarTransactionController extends BaseController
{
    @Autowired
    private IUsedCarTransactionService usedCarTransactionService;

    /**
     * 查询车辆交易记录（管理车辆交易流程）列表
     */
    @RequiresPermissions("usedcar:transaction:list")
    @GetMapping("/list")
    public TableDataInfo list(UsedCarTransaction usedCarTransaction)
    {
        startPage();
        List<UsedCarTransaction> list = usedCarTransactionService.selectUsedCarTransactionList(usedCarTransaction);
        return getDataTable(list);
    }

    /**
     * 导出车辆交易记录（管理车辆交易流程）列表
     */
    @RequiresPermissions("usedcar:transaction:export")
    @Log(title = "车辆交易记录（管理车辆交易流程）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UsedCarTransaction usedCarTransaction)
    {
        List<UsedCarTransaction> list = usedCarTransactionService.selectUsedCarTransactionList(usedCarTransaction);
        ExcelUtil<UsedCarTransaction> util = new ExcelUtil<UsedCarTransaction>(UsedCarTransaction.class);
        util.exportExcel(response, list, "车辆交易记录（管理车辆交易流程）数据");
    }

    /**
     * 获取车辆交易记录（管理车辆交易流程）详细信息
     */
    @RequiresPermissions("usedcar:transaction:query")
    @GetMapping(value = "/{transactionId}")
    public AjaxResult getInfo(@PathVariable("transactionId") Long transactionId)
    {
        return success(usedCarTransactionService.selectUsedCarTransactionByTransactionId(transactionId));
    }

    /**
     * 新增车辆交易记录（管理车辆交易流程）
     */
    @RequiresPermissions("usedcar:transaction:add")
    @Log(title = "车辆交易记录（管理车辆交易流程）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UsedCarTransaction usedCarTransaction)
    {
        return toAjax(usedCarTransactionService.insertUsedCarTransaction(usedCarTransaction));
    }

    /**
     * 修改车辆交易记录（管理车辆交易流程）
     */
    @RequiresPermissions("usedcar:transaction:edit")
    @Log(title = "车辆交易记录（管理车辆交易流程）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UsedCarTransaction usedCarTransaction)
    {
        return toAjax(usedCarTransactionService.updateUsedCarTransaction(usedCarTransaction));
    }

    /**
     * 删除车辆交易记录（管理车辆交易流程）
     */
    @RequiresPermissions("usedcar:transaction:remove")
    @Log(title = "车辆交易记录（管理车辆交易流程）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{transactionIds}")
    public AjaxResult remove(@PathVariable Long[] transactionIds)
    {
        return toAjax(usedCarTransactionService.deleteUsedCarTransactionByTransactionIds(transactionIds));
    }
}
